home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Graphics / GraphicsWorkshop / Source / Converters / PCX_SCRATCH / kludge.m < prev    next >
Encoding:
Text File  |  1993-01-14  |  1.5 KB  |  89 lines

  1. #import <stdio.h>
  2. #import <stdlib.h>
  3. #import <appkit/NXBitmapImageRep.h>
  4. #import <streams/streams.h>
  5. #import "kludge.h"
  6.  
  7. static int                aC;
  8. static int                w, h;
  9. static id                tmpImage;
  10. static unsigned char    *data[5];
  11.     
  12.  
  13. NXStream *pcx_openr(char *name)
  14. {
  15.     NXStream        *tFile;
  16.     FILE            *myFile;
  17.     
  18.     myFile = fopen(name, "r");
  19.     if (myFile) {
  20.         tFile = NXOpenFile(fileno(myFile), NX_READONLY);
  21.         if (tFile) {
  22.             return tFile;
  23.         }
  24.     }
  25.  
  26.     fprintf(stderr, "Unable to open %s\n", name);
  27.  
  28.     return NULL;
  29. }
  30.  
  31. id pcx_allocarray(int width, int height)
  32. {
  33.     tmpImage = [[NXBitmapImageRep alloc] initData: NULL
  34.                     pixelsWide:         width
  35.                     pixelsHigh:        height
  36.                     bitsPerSample:    8
  37.                     samplesPerPixel:    3
  38.                     hasAlpha:        NO
  39.                     isPlanar:            YES
  40.                     colorSpace:        NX_RGBColorSpace
  41.                     bytesPerRow:        0
  42.                     bitsPerPixel:        0];
  43.     w = width;
  44.     h = height;
  45.     [tmpImage getDataPlanes: data];
  46.     return tmpImage;
  47. }
  48.  
  49. void pcx_init(int argc, char *argv[])
  50. {
  51.     aC = argc;
  52. }
  53.  
  54. void pcx_usage(char *mes)
  55. {
  56.     fprintf(stderr, "%s\n", mes);
  57.     exit(1);
  58. }
  59.  
  60. id pcx_close(NXStream *file)
  61. {
  62.     return tmpImage;
  63.  
  64. //    NXStream    *myStream;
  65. //    FILE        *myFile;
  66.     
  67. //    myFile = fopen("out.tiff", "w");
  68. //    myStream = NXOpenFile(fileno(myFile), NX_WRITEONLY);
  69. //    [tmpImage writeTIFF: myStream];
  70. //    NXClose(myStream);
  71. //    fclose(myFile);
  72.  
  73. //    NXClose(file);
  74. }
  75.  
  76. void pcx_error(char *err)
  77. {
  78.     fprintf(stderr, "%s\n", err);
  79.     exit(1);
  80. }
  81.  
  82. void PCX_ASSIGN(int x, int y, unsigned char r, unsigned char g, unsigned char b)
  83. {
  84. //    if ((x == 0) && !(y % 10)) fprintf(stderr, "%d,%d\n", x, y);
  85.     data[0][y * w + x] = r; 
  86.     data[1][y * w + x] = g; 
  87.     data[2][y * w + x] = b; 
  88. }
  89.